package com.example.ending_demo.utils;

import java.sql.*;

public class DBUtils {
    public static Connection getConnection(){
        try {
            String url = "jdbc:mysql://localhost:3306/address";
            String user = "root";
            String pwd = "123456";
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection(url,user,pwd);
            return conn;
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public static void release(ResultSet rs, Statement stat, Connection conn){
        try {
            rs.close();
            stat.close();
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public static void release(Statement stat,Connection conn){
        try {
            stat.close();
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


}
